package com.dminvoicemanager;

/*import info.androidhive.sqlite.model.Tag;
 import info.androidhive.sqlite.model.Todo;
 */

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class DM_ApplicationDBLoader extends SQLiteOpenHelper {

	// Database Name
	private static final String DATABASE_NAME = "dminvoicemanager.db";
	// Master Tables
	private String SERVER_DB_LIST = "serverdb";
	private String USER_SETTINGS = "usersettings";
	private String ITEM_AREA = "fArea";
	private String ITEM_COMPANY_SETTING = "fCompanySetting";
	private String ITEM_CONTROL = "fControl";
	private String ITEM_DEBTOR = "fDebtor";
	private String ITEM_LOC_DETAILS = "fItemLoc";
	private String ITEM_LOCATION = "fLocation";
	private String ITEM_PRICE = "fItemPri";
	private String ITEMS = "fItems";
	private String INV_COMPANY_BRANCH = "FCompanyBranch";
	private String INV_SAL_REP = "fSalRep";
	private String SALES_ORD_REASON = "fReason";
	private String SALES_REP_ROUTE = "fRoute";
	private String SALES_REP_ROUTEDET = "fRouteDet";
	private String BANK_DETAILS = "fBank";
	private String USER_EXPENSE = "fExpense";
	private String TOWN_DETAILS = "fTown";
	private String MERCH_DETAILS = "FMerch";
	private String DEBMERCH_DETAILS = "FDebMerch";
	private String RETAILER_SUM = "FRetailScrSum";
	private String YEARS_LIST = "FYearsList";
	private String MONTH_LIST = "FMonthList";
	private String SERVER_DETAILS = "serverinfo";
	private String SALES_DEALER = "fDealer";
	private String DB_VERSION_UPGRADE = "Fdb_version_upgrade";

	private String FTRGCAPUL = "FTrgCapUL";
	private String FTYPE = "fType";
	private String FSUBBRAND = "fSubBrand";
	private String FGROUP = "fGroup";
	private String FSKU = "fSku";
	private String FBRAND = "fbrand";

	// Main Invoice
	private String TEMP_REP_INVOICESUMERY = "frepInvoiceSumery";
	private String INV_DETAILS = "FinvDet";
	private String INV_HEADER = "FinvHed";

	// Stock Loading
	private String TEMP_STOCK_LOADING_SUMMARY = "frepStockLoadingSummary";
	private String STOCK_LOAD_HEAD = "fLoadhed";
	private String STOCK_LOAD_DETAIL = "fLoadDet";

	// Sales Order
	private String STOCK_ORDER_INVOICESUMERY = "fstockordInvoiceSumery";
	private String STOCK_ORDER_HEAD = "FOrdHed";
	private String STOCK_ORDER_DETAIL = "FOrddet";
	private String TEMPSTOCK_ORDER_HEAD = "TempFOrdHed";
	private String TEMPSTOCK_ORDER_DETAIL = "TempFOrddet";

	// Stock UnLoading
	private String TEMP_STOCK_LOADING_SUMMARYUN = "frepStockLoadingSummaryUn";
	private String STOCK_LOAD_HEADUN = "fUnLoadhed";
	private String STOCK_LOAD_DETAILUN = "fUnLoadDet";

	// Stock Damage
	private String TEMP_STOCK_LOADING_SUMMARYDAM = "frepStockLoadingSummaryDam";
	private String STOCK_LOAD_HEADDAM = "fDamhed";
	private String STOCK_LOAD_DETAILDAM = "fDamdet";

	// Cash /Receipt header
	private String TEMP_RECEIPT_SUMMARY = "fReceiptSummary";
	private String RECEIPT_HEADER = "fDRecHed";
	private String RECEIPT_DETAILS = "fDRecDet";

	// Adjustment
	private String TEMP_ADJUSTMENT_SUMMARY = "FAdjustmentSummary";
	private String ADJUST_ADDITION_HEADER = "FAdjHed";
	private String ADJUST_ADDITION_DETAILS = "FAdjDet";

	// Expense
	private String TEMP_DAYEXPENSE_SUMMARY = "FDayExpSummary";
	private String DAYEXPENSE_HEADER = "FDayExpHed";
	private String DAYEXPENSE_DETAILS = "FDayExpDet";

	// Itinerary Report
	private String ITINERARY_HEAD = "FItenrHed";
	private String ITINERARY_DETAILS = "FItenrDet";
	private String ITINERARY_DETTAIL_DET = "FIteDetDet";

	private String RECEIPT_INVOICES = "FDDbNote";

	// None Productive Calls
	private String DAILY_NONE_PRDCALLS_HEAD = "fNonePrd";

	// Meter Reading
	private String METER_READING_HEAD = "fMeterRead";

	// GPS Records
	private String FREPGPS = "fRepGps";
	private String GPS_USER_DB = "fUserGps";
	
	// Logcat tag
	private static final String LOG = "DatabaseHelper";

	// Database Version
	private static final int DATABASE_VERSION = 6;
	private static final String TAG = null;

	public DM_ApplicationDBLoader(Context context) {
		super(context, DATABASE_NAME, null, DATABASE_VERSION);
		// this.myContext = context;
	}

	@Override
	public void onCreate(SQLiteDatabase mydb) {
		try {
			Log.v(TAG, "onCreate Call");
			mydb.execSQL("create table if not exists "
					+ DB_VERSION_UPGRADE
					+ "(dbversion_id integer primary key autoincrement,oldversion text not null,newversion text not null,upgradeDone text not null,activeupgrade text not null);");

			mydb.execSQL("create table if not exists "
					+ SALES_DEALER
					+ "(_id integer primary key autoincrement,DealCode text not null,DealName text not null,DealAdd1 text not null,DealAdd2 text not null,DealAdd3 text not null,DealTele text not null,DealMob text not null,DealEMail text not null,Status text not null,Distance text not null,DealGdCode text not null,CusTypCode text not null,AddUser text not null,AddDate text not null,AddMach text not null,RecordId text not null);");

			mydb.execSQL("create table if not exists "
					+ YEARS_LIST
					+ "(year_id integer primary key autoincrement,yearname text not null);");

			mydb.execSQL("create table if not exists "
					+ MONTH_LIST
					+ "(month_id integer primary key autoincrement,monthindex text not null,monthname text not null);");

			mydb.execSQL("create table if not exists "
					+ SERVER_DETAILS
					+ "(server_id integer primary key autoincrement,serverurl text not null,portval text not null,serverdbname text not null,activeproperty text not null);");

			mydb.execSQL("create table if not exists "
					+ SERVER_DB_LIST
					+ "(sdb_id integer primary key autoincrement,sdbname text not null);");

			mydb.execSQL("create table if not exists "
					+ USER_SETTINGS
					+ "(_id integer primary key autoincrement,username text not null,lrepprefix text not null,lreploccode text not null,currentStOrdNo text not null,locationCode text not null,receiptCode text not null,serverDbName text not null,printerMac text not null,repareacode text not null,repdealcode text not null,reproutecode text not null);");

			mydb.execSQL("create table if not exists "
					+ ITEM_AREA
					+ "(farea_id integer primary key autoincrement,AreaCode text not null,AreaName text not null,RegCode text not null,DealCode text not null,AddUser text not null,AddDatefarea text not null,AddMach text not null,RecordId text not null,timestamp_column text not null);");

			mydb.execSQL("create table if not exists "
					+ TEMP_REP_INVOICESUMERY
					+ "(remprepinv_id integer primary key autoincrement,repusername text not null,repprefix text not null,tempRepInvNoCode text not null,tempRepInvSerial text not null,invoiceComplete text not null,activeInvoice text not null,activeInvoiceValue text not null,activeInvItemDiscount text not null,activeInvCusDiscount text not null,activeInvCusDiscountValue text not null,InvoiceCustomerCode text not null,InvoiceCustomerName text not null,InvoiceSynchState text not null,recordDate text not null,recordSynchDate text not null,invlateststate text not null,activeInvoiceReturnValue text not null,activeInvoiceRemarks text not null,invoiceNoOfItems text not null,invoiceRef text not null,invoiceRefStl text not null);");

			mydb.execSQL("create table if not exists "
					+ ITEM_LOCATION
					+ "(flocation_id integer primary key autoincrement,AddMach text not null,AddUser text not null,Address1 text not null,Address2 text not null,Address3 text not null,Contact text not null,EMail text not null,FaxNo text not null,LocCode text not null,LocName text not null,LoctCode text not null,RecordId text not null,RepCode text not null,TeleNo text not null,LocAddDate text not null);");

			mydb.execSQL("create table if not exists "
					+ ITEMS
					+ "(_id integer primary key autoincrement,SKUCode text not null,ItemCode text not null,MapCode text not null,ItemName text not null,VenPcode text not null,GroupCode text not null,TypeCode text not null,TaxComCode text not null,UnitCode text not null,SkuSizCode text not null,ItemStatus text not null,ReOrderLvl text not null,ReOrderQty text not null,AvgPrice text not null,PurAcc text not null,PurRetAcc text not null,SVATAcc text not null,ExportAcc text not null,IndrExAcc text not null,SalAcc text not null,SalRetAcc text not null,DisAcc text not null,ClsStkAcc text not null,StkInAcc text not null,PrilCode text not null,BrandCode text not null,SBrandCode text not null,NOUCase text not null,OrdSeq text not null,AddUser text not null,AddDatefitem text not null,AddMach text not null,RecordId text not null,timestamp_column text not null,MustSale  text not null);");

			mydb.execSQL("create table if not exists "
					+ ITEM_PRICE
					+ "(fitempri_id integer primary key autoincrement,SKUCode text not null,ItemCode text not null,PrilCode text not null,PriRDate text not null,Price text not null,AddUser text not null,AddDateIP text not null,AddMach text not null,Txnuser text not null,TxnDate text not null,TxnMach text not null,RecordId text not null);");

			mydb.execSQL("create table if not exists "
					+ ITEM_LOC_DETAILS
					+ "(flocdet_id integer primary key autoincrement,LocCode text not null,ItemCode text not null,QOH text not null,RecordId text not null,timestamp_column text not null,syncRec text not null);");

			mydb.execSQL("create table if not exists "
					+ ITEM_DEBTOR
					+ "(_id integer primary key autoincrement,DebCode text not null,DebName text not null,DebAdd1 text not null,DebAdd2 text not null,DebAdd3 text not null,DebTele text not null,DebMob text not null,DebEMail text not null,CretDate text not null,OutDis text not null,RemDis text not null,TownCode text not null,AreaCode text not null,DebCatCode text not null,DbGrCode text not null,DebClsCode text not null,Status text not null,DebLylty text not null,DealCode text not null,AddUser text not null,AddDateDEB text not null,AddMach text not null,RecordId text not null,timestamp_column text not null,CrdPeriod text not null,ChkCrdPrd text not null,CrdLimit text not null,ChkCrdLmt text not null,RepCode text not null,RankCode text not null,txndate text not null,TranBatch text not null,DebSumary text not null);");

			mydb.execSQL("create table if not exists "
					+ ITEM_CONTROL
					+ "(fcontrol_id integer primary key autoincrement,ComName text not null,ComAdd1 text not null,ComAdd2 text not null,ComAdd3 text not null,comtel1 text not null,comtel2 text not null,comfax1 text not null,comemail text not null,comweb text not null,confyear text not null,contyear text not null,comRegNo text not null,ConfTxn text not null,ContTxn text not null,Crystalpath text not null,VatCmTaxNo text not null,NbtCmTaxNo text not null,SysId text not null,DealCode text not null,basecur text not null,BalgCrLm text not null,conage1 text not null,conage2 text not null,conage3 text not null,conage4 text not null,conage5 text not null,conage6 text not null,conage7 text not null,conage8 text not null,conage9 text not null,conage10 text not null,conage11 text not null,conage12 text not null,conage13 text not null,conage14 text not null);");

			mydb.execSQL("create table if not exists "
					+ ITEM_COMPANY_SETTING
					+ "(fcomset_id integer primary key autoincrement,cSettingsCode text not null,cSettingGrp text not null,cLocationChar text not null,cCharVal text not null,nNumVal text not null,cRemarks text not null,nType text not null,bUpdateFlag text not null,cCompanyCode text not null,recordid text not null,timestamp_column text not null);");

			mydb.execSQL("create table if not exists "
					+ INV_DETAILS
					+ "(invdet_id integer primary key autoincrement,RefNo text not null,TxnDate text not null,TxnType text not null,SeqNo text not null,Itemcode text not null,Txnseqno text not null,SellPrice text not null,BSellPrice text not null,TSellPrice text not null,BTSellPrice text not null,CostPrice text not null,CaseQty text not null,Type text not null,PiceQty text not null,Qty text not null,BalQty text not null,DisPer text not null,DisAmt text not null,BDisAmt text not null,TaxAmt text not null,BTaxAmt text not null,Amt text not null,BAmt text not null,ReaCode text not null,Linkrec text not null,RecordId text not null,itemDescription text not null,refInvoiceDetNo text not null,refInvoiceDetCode text not null,refInvitemCaseQty text not null,refInvStockOrderNo text not null,invdetSync text not null,invsysdate text not null,itemdisper text not null,itemdisperval text not null,reasonCode  text not null,reasonDesc  text not null,itemUnitPrice text not null);");

			mydb.execSQL("create table if not exists "
					+ INV_HEADER
					+ "(invhead_id integer primary key autoincrement,RefNo text not null,RefNo1 text not null,InvType text not null,TxnDate text not null,ManuRef text not null,DealCode text not null,RepCode text not null,AreaCode text not null,RouteCode text not null,DebCode text not null,LocCode text not null,Remarks text not null,CostCode text not null,CurCode text not null,CurRate text not null,TxnType text not null,InvAmt text not null,OutDis text not null,InvDis text not null,TotMkrAmt text not null,UnOvAmt text not null,TotalDis text not null,TotalAmt text not null,AddUser text not null,AddDateInvHead text not null,AddMach text not null,prtcopy text not null,RecordId text not null,timestamp_column text not null,refInvoiceHeaderNo text not null,refInvoiceHeaderCode text not null,invhedSync text not null,outDisVal text not null);");

			mydb.execSQL("create table if not exists "
					+ SALES_REP_ROUTE
					+ "(route_id integer primary key autoincrement,RepCode text not null,RouteCode text not null,RouteName text not null,RecordId text not null,AddDate text not null,AreaCode text not null,DealCode text not null,FreqNo text not null,Km text not null,MinProcall text not null,RDAloRate text not null,RDTarget text not null,Remarks text not null,Status text not null,Tonnage text not null);");

			mydb.execSQL("create table if not exists "
					+ SALES_REP_ROUTEDET
					+ "(fRouteDet_id integer primary key autoincrement,RecordId text not null,DebCode text not null,RouteCode text not null);");

			mydb.execSQL("create table if not exists "
					+ BANK_DETAILS
					+ "(bankre_id integer primary key autoincrement,RecordId text not null,bankcode text not null,bankname text not null,bankaccno text not null,Branch text not null,bankadd1 text not null,bankadd2 text not null,AddDate text not null);");

			mydb.execSQL("create table if not exists "
					+ SALES_ORD_REASON
					+ "(freason_id integer primary key autoincrement,AddDate text not null,AddMach text not null,AddUser text not null,ReaCode text not null,ReaName text not null,ReaTcode text not null,RecordId text not null,Type text not null);");

			mydb.execSQL("create table if not exists "
					+ USER_EXPENSE
					+ "(uexp_id integer primary key autoincrement,ExpCode text not null,ExpGrpCode text not null,ExpName text not null,RecordId text not null,Status text not null,AddMach text not null,AddUser text not null);");

			mydb.execSQL("create table if not exists "
					+ TOWN_DETAILS
					+ "(townre_id integer primary key autoincrement,RecordId text not null,TownCode text not null,TownName text not null,DistrCode text not null,AddDate text not null,AddMach text not null,AddUser text not null);");

			mydb.execSQL("create table if not exists "
					+ MERCH_DETAILS
					+ "(merchre_id integer primary key autoincrement,RecordId text not null,MerchCode text not null,MerchName text not null,AddUser text not null,AddMach text not null,AddDate text not null);");

			mydb.execSQL("create table if not exists "
					+ DEBMERCH_DETAILS
					+ "(debmerchre_id integer primary key autoincrement,DebCode text not null,MerchCode text not null,txndate text not null,TranBatch text not null);");

			mydb.execSQL("create table if not exists "
					+ RETAILER_SUM
					+ "(retsum_id integer primary key autoincrement,DebCode text not null,SumMerchCode text not null,retSumaddDate text not null);");

			// New Master Tables
			mydb.execSQL("create table if not exists "
					+ FTRGCAPUL
					+ "(ftrg_id integer primary key autoincrement,AddDate text not null,AddMach text not null,AddUser text not null,DealCode text not null,Month text not null,Qty text not null,RecordId text not null,RepCode text not null,SKUCode text not null,Year text not null);");

			mydb.execSQL("create table if not exists "
					+ FTYPE
					+ "(ftype_id integer primary key autoincrement,AddDate text not null,AddMach text not null,AddUser text not null,RecordId text not null,TypeCode text not null,TypeName text not null);");

			mydb.execSQL("create table if not exists "
					+ FSUBBRAND
					+ "(fsubbrand_id integer primary key autoincrement,AddDate text not null,AddMach text not null,AddUser text not null,RecordId text not null,SBrandCode text not null,SBrandName text not null);");

			mydb.execSQL("create table if not exists "
					+ FGROUP
					+ "(fgroup_id integer primary key autoincrement,AddDate text not null,AddMach text not null,AddUser text not null,GroupCode text not null,GroupName text not null,RecordId text not null);");

			mydb.execSQL("create table if not exists "
					+ FSKU
					+ "(fsku_id integer primary key autoincrement,AddDate text not null,AddMach text not null,AddUser text not null,BrandCode text not null,GroupCode text not null,ItemStatus text not null,MustSale text not null,NOUCase text not null,OrdSeq text not null,RecordId text not null,SBrandCode text not null,SKUCode text not null,SkuName text not null,SkuSizCode text not null,Tonnage text not null,TypeCode text not null,Unit text not null);");

			mydb.execSQL("create table if not exists "
					+ FBRAND
					+ "(fbrand_id integer primary key autoincrement,AddMach text not null,AddUser text not null,BrandCode text not null,BrandName text not null,RecordId text not null);");

			// Stock Orders
			mydb.execSQL("create table if not exists "
					+ STOCK_ORDER_INVOICESUMERY
					+ "(remprepinv_id integer primary key autoincrement,repusername text not null,repprefix text not null,tempRepInvNoCode text not null,tempRepInvSerial text not null,invoiceComplete text not null,activeInvoice text not null,activeInvoiceValue text not null,activeInvItemDiscount text not null,activeInvCusDiscount text not null,activeInvCusDiscountValue text not null,InvoiceCustomerCode text not null,InvoiceCustomerName text not null,InvoiceSynchState text not null,recordDate text not null,recordSynchDate text not null,invlateststate text not null,activeInvoiceReturnValue text not null,activeInvoiceRemarks text not null,invoiceNoOfItems text not null,invoiceRef text not null,invoiceRefStl text not null,invoicedelidate text not null,invManuRefNo text not null);");

			mydb.execSQL("create table if not exists "
					+ STOCK_ORDER_HEAD
					+ "(stohed_id integer primary key autoincrement,AddMach text not null,AddUser text not null,AreaCode text not null,CostCode text not null,CurCode text not null,CurRate text not null,DealCode text not null,DebCode text not null,InvAmt text not null,InvDis text not null,InvFlg text not null,LocCode text not null,ManuRef text not null,OutDis text not null,RecordId text not null,RefNo text not null,Remarks text not null,RepCode text not null,RouteCode text not null,TotMkrAmt text not null,TotalAmt text not null,TotalDis text not null,TranBatch text not null,TxnType text not null,UnOvAmt text not null,prtcopy text not null,TxnDate text not null,stOrderComplete text not null,stordhedSync text not null,outDisVal text not null,ohAddDate text not null,delvDate text not null);");

			mydb.execSQL("create table if not exists "
					+ STOCK_ORDER_DETAIL
					+ "(stodet_id integer primary key autoincrement,Amt text not null,BAmt text not null,BDisAmt text not null,BSellPrice text not null,BTSellPrice text not null,BTaxAmt text not null,BalQty text not null,CaseQty text not null,CostPrice text not null,DisAmt text not null,DisPer text not null,Itemcode text not null,PiceQty text not null,Qty text not null,ReaCode text not null,RecordId text not null,RefNo text not null,SellPrice text not null,SeqNo text not null,TSellPrice text not null,TaxAmt text not null,TxnType text not null,Txnseqno text not null,Type text not null,TxnDate text not null,storddetSync text not null,itemdisper text not null,itemdisperval text not null,reasonDesc text not null,odAddDate text not null,itemUnitPrice text not null,caseUnitsQty text not null);");

			mydb.execSQL("create table if not exists "
					+ TEMPSTOCK_ORDER_DETAIL
					+ "(invdet_id integer primary key autoincrement,RefNo text not null,TxnDate text not null,TxnType text not null,SeqNo text not null,Itemcode text not null,Txnseqno text not null,SellPrice text not null,BSellPrice text not null,TSellPrice text not null,BTSellPrice text not null,CostPrice text not null,CaseQty text not null,Type text not null,PiceQty text not null,Qty text not null,BalQty text not null,DisPer text not null,DisAmt text not null,BDisAmt text not null,TaxAmt text not null,BTaxAmt text not null,Amt text not null,BAmt text not null,ReaCode text not null,Linkrec text not null,RecordId text not null,itemDescription text not null,refInvoiceDetNo text not null,refInvoiceDetCode text not null,refInvitemCaseQty text not null,refInvStockOrderNo text not null,refReasondetails text not null,itemdisper text not null,itemdisperval text not null,odtAddDate text not null,itemUnitPrice text not null);");

			mydb.execSQL("create table if not exists "
					+ TEMPSTOCK_ORDER_HEAD
					+ "(invhead_id integer primary key autoincrement,RefNo text not null,RefNo1 text not null,InvType text not null,TxnDate text not null,ManuRef text not null,DealCode text not null,RepCode text not null,AreaCode text not null,RouteCode text not null,DebCode text not null,LocCode text not null,Remarks text not null,CostCode text not null,CurCode text not null,CurRate text not null,TxnType text not null,InvAmt text not null,OutDis text not null,InvDis text not null,TotMkrAmt text not null,UnOvAmt text not null,TotalDis text not null,TotalAmt text not null,AddUser text not null,AddDateInvHead text not null,AddMach text not null,prtcopy text not null,RecordId text not null,timestamp_column text not null,refInvoiceHeaderNo text not null,refInvoiceHeaderCode text not null);");

			// Stock Loading
			mydb.execSQL("create table if not exists "
					+ STOCK_LOAD_HEAD
					+ "(RecordId integer primary key autoincrement,RefNo text not null,TxnDate text not null,ManuRef text not null,CostCode text not null,Remarks text not null,TxnType text not null,TotalAmt text not null,DelPersn text not null,DelAdd1 text not null,DelAdd2 text not null,DelAdd3 text not null,VehicalNo text not null,GlPost text not null,GlBatch text not null,AddUser text not null,AddDatestlh text not null,AddMach text not null,TranFlg text not null,ItemType text not null,stlhedSync text not null);");

			mydb.execSQL("create table if not exists "
					+ STOCK_LOAD_DETAIL
					+ "(RecordId integer primary key autoincrement,RefNo text not null,TxnDate text not null,LocCode text not null,TxnType text not null,SeqNo text not null,ItemCode text not null,CaseQty text not null,PiceQty text not null,Qty text not null,CostPrice text not null,Amt text not null,RecordDate text not null,RecordChecked text not null,LitemName text not null,LitemQOH text not null,CaseUnits text not null,stldetSync text not null);");

			mydb.execSQL("create table if not exists "
					+ TEMP_STOCK_LOADING_SUMMARY
					+ "(temprepStLoad_id integer primary key autoincrement,stlrepusername text not null,stlrepprefix text not null,tempRepStLoadCode text not null,tempRepStLoadSerial text not null,tempRepStLoadRefNo text not null,stLoadComplete text not null,stLoadActive text not null,stLoadActiveValue text not null,stLoadstartDate text not null,fromLocName text not null,toLocName text not null);");

			mydb.execSQL("create table if not exists "
					+ INV_COMPANY_BRANCH
					+ "(fcombra_id integer primary key autoincrement,BranchCode text not null,RecordId text not null,cSettingsCode text not null,nNumVal text not null);");

			mydb.execSQL("create table if not exists "
					+ INV_SAL_REP
					+ "(fsalrep_id integer primary key autoincrement,ASECode text not null,AreaCode text not null,DealCode text not null,RecordId text not null,RepCode text not null,RepPrefix text not null,RepTCode text not null,repPhoneNo text not null,RepName text not null,RepEMail text not null,RepMob text not null);");

			// Stock UnLoading
			mydb.execSQL("create table if not exists "
					+ STOCK_LOAD_HEADUN
					+ "(RecordId integer primary key autoincrement,RefNo text not null,TxnDate text not null,ManuRef text not null,CostCode text not null,Remarks text not null,TxnType text not null,TotalAmt text not null,DelPersn text not null,DelAdd1 text not null,DelAdd2 text not null,DelAdd3 text not null,VehicalNo text not null,GlPost text not null,GlBatch text not null,AddUser text not null,AddDatestlh text not null,AddMach text not null,TranFlg text not null,ItemType text not null,stlhedunSync text not null,IntangFlg text not null);");

			mydb.execSQL("create table if not exists "
					+ STOCK_LOAD_DETAILUN
					+ "(RecordId integer primary key autoincrement,RefNo text not null,TxnDate text not null,LocCode text not null,TxnType text not null,SeqNo text not null,ItemCode text not null,CaseQty text not null,PiceQty text not null,Qty text not null,CostPrice text not null,Amt text not null,RecordDate text not null,RecordChecked text not null,LitemName text not null,LitemQOH text not null,CaseUnits text not null,stldetunSync text not null,IntangFlg text not null);");

			mydb.execSQL("create table if not exists "
					+ TEMP_STOCK_LOADING_SUMMARYUN
					+ "(temprepStLoad_id integer primary key autoincrement,stlrepusername text not null,stlrepprefix text not null,tempRepStLoadCode text not null,tempRepStLoadSerial text not null,tempRepStLoadRefNo text not null,stLoadComplete text not null,stLoadActive text not null,stLoadActiveValue text not null,stLoadstartDate text not null,fromLocName text not null,toLocName text not null);");

			// Stock Damage
			mydb.execSQL("create table if not exists "
					+ STOCK_LOAD_HEADDAM
					+ "(RecordId integer primary key autoincrement,RefNo text not null,TxnDate text not null,ManuRef text not null,DealCode text not null,Remarks text not null,TxnType text not null,TotalAmt text not null,CostCode text not null,ReaCode text not null,GlPost text not null,GlBatch text not null,AddUser text not null,AddDatestlh text not null,AddMach text not null,ItemType text not null,stldmhedSync text not null);");

			mydb.execSQL("create table if not exists "
					+ STOCK_LOAD_DETAILDAM
					+ "(RecordId integer primary key autoincrement,RefNo text not null,TxnDate text not null,LocCode text not null,TxnType text not null,SeqNo text not null,ItemCode text not null,CaseQty text not null,PiceQty text not null,Qty text not null,CostPrice text not null,Amt text not null,RecordDate text not null,RecordChecked text not null,LitemName text not null,LitemQOH text not null,CaseUnits text not null,reaCode text not null,stldmdetSync text not null);");

			mydb.execSQL("create table if not exists "
					+ TEMP_STOCK_LOADING_SUMMARYDAM
					+ "(temprepStLoad_id integer primary key autoincrement,stlrepusername text not null,stlrepprefix text not null,tempRepStLoadCode text not null,tempRepStLoadSerial text not null,tempRepStLoadRefNo text not null,stLoadComplete text not null,stLoadActive text not null,stLoadActiveValue text not null,stLoadstartDate text not null,fromLocName text not null,toLocName text not null);");

			// Cash / Cheque Receipt
			mydb.execSQL("create table if not exists "
					+ TEMP_RECEIPT_SUMMARY
					+ "(tempReceipt_id integer primary key autoincrement,treceiptusername text not null,treceiptprefix text not null,treceiptCode text not null,treceiptSerial text not null,treceiptRefNo text not null,treceiptComplete text not null,treceiptActive text not null,treceiptManualno text not null,treceiptstartDate text not null,treceiptCusno text not null,treceiptCusName text not null,treceiptPayType text not null,treceiptChequeno text not null,treceiptChequeDate text not null,treceiptBankNo text not null,treceiptBankName text not null,treceiptReceiptAmt text not null,treceiptReceiptBalAmt text not null,treceiptRemark text not null);");

			mydb.execSQL("create table if not exists "
					+ RECEIPT_HEADER
					+ "(reched_id integer primary key autoincrement,RefNo text not null,ManuRef text not null,SaleRefNo text not null,RepCode text not null,TxnType text not null,Chqno text not null,ChqDate text not null,TxnDate text not null,CurCode text not null,CurRate text not null,DebCode text not null,TotalAmt text not null,BTotalAmt text not null,BankCur text not null,BankRate text not null,BankAmt text not null,BankCharge text not null,BBankChg text not null,GnLsCal text not null,DbAcc text not null,PayType text not null,PrtCopy text not null,GlPost text not null,Remarks text not null,CardSlipNo text not null,ExpDate text not null,CrdTypCode text not null,CCBankAmt text not null,GlBatch text not null,AddUser text not null,AddMach text not null,AddrecDate text not null,recipthedSync text not null);");

			mydb.execSQL("create table if not exists "
					+ RECEIPT_DETAILS
					+ "(RecDet_id integer primary key autoincrement,RefNo text not null,RefNo1 text not null,SaleRefNo text not null,ManuRef text not null,TxnType text not null,TxnDate text not null,DtxnDate text not null,DtxnType text not null,DCurCode text not null,DCurRate text not null,OCurRate text not null,RepCode text not null,Amt text not null,BAmt text not null,GainLosAmt text not null,BnkChgs text not null,BBnkChgs text not null,AloAmt text not null,OvPayAmt text not null,OvPayBal text not null,reciptdetSync text not null,recsysdate text not null);");

			mydb.execSQL("create table if not exists "
					+ RECEIPT_INVOICES
					+ "(recinv_id integer primary key autoincrement,RecordId text not null,RefNo text not null,RefInv text not null,SaleRefNo text not null,ManuRef text not null,TxnType	text not null,TxnDate text not null,CurCode text not null,CurRate text not null,DebCode text not null,RepCode text not null,TaxComCode text not null,TaxAmt text not null,BTaxAmt text not null,Amt text not null,BAmt text not null,TotBal text not null,TotBal1 text not null,OvPayAmt text not null,Remarks text not null,CrAcc text not null,PrtCopy text not null,GlPost text not null,glbatch text not null,AddUser text not null,AddDate	text not null,AddMach	text not null,RefNo1	text not null);");

			// Adjustment
			mydb.execSQL("create table if not exists "
					+ TEMP_ADJUSTMENT_SUMMARY
					+ "(adjustsum_id integer primary key autoincrement,username text not null,refCode text not null,refSerial text not null,currentState text not null,activeMode text not null,LocCode text not null,LocName text not null,TotalAmount text not null,ManuRefNo text not null,AdjustTxnType text not null);");

			mydb.execSQL("create table if not exists "
					+ ADJUST_ADDITION_DETAILS
					+ "(fadjdet_id integer primary key autoincrement,RefNo text not null,TxnDate text not null,TxnType text not null,SeqNo text not null,ItemCode text not null,CaseQty text not null,PiceQty text not null,Qty text not null,CostPrice text not null,Amt text not null,ReaCode text not null,ItemName text not null,QOH text not null,ReaName text not null,CaseUnits text not null,CasePrice text not null,adjDetSync text not null);");

			mydb.execSQL("create table if not exists "
					+ ADJUST_ADDITION_HEADER
					+ "(fadjhed_id integer primary key autoincrement,RefNo text not null,TxnDate text not null,CostCode text not null,ManuRef text not null,DealCode text not null,RefNo2 text not null,TxnType text not null,TotalAmt text not null,Remarks text not null,LocCode text not null,ReaCode text not null,GlPost text not null,GlBatch text not null,AddUser text not null,AddDate text not null,AddMach text not null,ItemType text not null,adjHedSync text not null);");

			// Day Expence
			mydb.execSQL("create table if not exists "
					+ TEMP_DAYEXPENSE_SUMMARY
					+ "(dexpsum_id integer primary key autoincrement,dexprepusername text not null,dexprepprefix text not null,dexprefcode text not null,dexprefnoserial text not null,dexpreComplete text not null,dexpreActive text not null,dexprefnocode text not null,dexpremark text not null,amountTot text not null);");

			mydb.execSQL("create table if not exists "
					+ DAYEXPENSE_HEADER
					+ "(dexphed_id integer primary key autoincrement,RefNo text not null,TxnDate text not null,RepName text not null,DealCode text not null,CostCode text not null,RepCode text not null,RegCode text not null,AreaCode text not null,Remarks text not null,AddUser text not null,AddDate text not null,AddMach text not null,TranBatch text not null);");

			mydb.execSQL("create table if not exists "
					+ DAYEXPENSE_DETAILS
					+ "(sdb_id integer primary key autoincrement,RefNo text not null,TxnDate text not null,SeqNo text not null,ExpCode text not null,Amt text not null,ExpName text not null);");

			// None Productive Calls
			mydb.execSQL("create table if not exists "
					+ DAILY_NONE_PRDCALLS_HEAD
					+ "(RecordId integer primary key autoincrement,RefNo text not null,TxnDate text not null,DebCode text not null,DebName text not null,Status text not null,stldmhedSync text not null,Reason text not null);");

			// Meter Reading
			mydb.execSQL("create table if not exists "
					+ METER_READING_HEAD
					+ "(RecordId integer primary key autoincrement,TxnDate text not null,StartRd text not null,EndRd text not null,PreviRd text not null,stldmhedSync text not null);");

			// Itinerary Report
			mydb.execSQL("create table if not exists "
					+ ITINERARY_HEAD
					+ "(fitenrhed_id integer primary key autoincrement,RefNo text not null,DealCode text not null,RepCode text not null,Year text not null,Month text not null,Remarks1 text not null,CostCode text not null,AddUser text not null,AddDate text not null,AddMach text not null,TranBatch text not null,TxnDate text not null,ItenrHedComplete text not null,ItenrHedActive text not null,ItinaryUser text not null,ItenrHedActiveSerial text not null,MonthName text not null,currentViewIti text not null,ItiRefIdentifire text not null);");

			mydb.execSQL("create table if not exists "
					+ ITINERARY_DETAILS
					+ "(fitenrdet_id integer primary key autoincrement,RefNo text not null,TxnDate text not null,RouteCode text not null,NoOutlet text not null,NoShcuCal text not null,RDTarget text not null,Remarks text not null,RouteName text not null,ActiveRec text not null,ActiveRecIdentifire text not null);");

			mydb.execSQL("create table if not exists "
					+ ITINERARY_DETTAIL_DET
					+ "(fitedetdet_id integer primary key autoincrement,RefNoDet not null,TxnDate not null,RouteCode not null,DebCode not null,DebName not null,ActiveRecDet text not null);");

			mydb.execSQL("create table if not exists "
					+ FREPGPS
					+ "(_id integer primary key autoincrement,longitude text not null,latitude text not null,emi_number text not null,device_time text not null,sync_state text not null);");
		
			  mydb.execSQL("create table if not exists "
						+ GPS_USER_DB
						+ "(_id integer primary key autoincrement,imei_no text not null,phone_no text not null,email_add text not null,sync_state text not null);");
		} catch (Exception e) {
		}

	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		// on upgrade drop older tables
		/*Log.v(TAG, "onUpgrade Call");
		Log.v(TAG, "oldVersion :" + oldVersion);
		Log.v(TAG, "newVersion :" + newVersion);

		String column_name_a = "RepName";
		String column_name_b = "RepEMail";
		String column_name_c = "RepMob";
		String column_name_d = "itemUnitPrice";
		String column_name_e = "serverdbname";
		String column_name_f = "activeproperty";
		String column_name_g = "caseUnitsQty";

		db.execSQL("ALTER TABLE " + INV_SAL_REP + " ADD COLUMN "
				+ column_name_a);
		db.execSQL("ALTER TABLE " + INV_SAL_REP + " ADD COLUMN "
				+ column_name_b);
		db.execSQL("ALTER TABLE " + INV_SAL_REP + " ADD COLUMN "
				+ column_name_c);

		db.execSQL("ALTER TABLE " + INV_DETAILS + " ADD COLUMN "
				+ column_name_d);

		db.execSQL("ALTER TABLE " + SERVER_DETAILS + " ADD COLUMN "
				+ column_name_e);
		db.execSQL("ALTER TABLE " + SERVER_DETAILS + " ADD COLUMN "
				+ column_name_f);

		db.execSQL("ALTER TABLE " + TEMPSTOCK_ORDER_DETAIL + " ADD COLUMN "
				+ column_name_d);
		db.execSQL("ALTER TABLE " + STOCK_ORDER_DETAIL + " ADD COLUMN "
				+ column_name_d);
		db.execSQL("ALTER TABLE " + STOCK_ORDER_DETAIL + " ADD COLUMN "
				+ column_name_g);*/

	}

}
